<template>
    <!-- 党务监督 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->
            <a-button
                class="mb12"
                icon="plus"
                type="primary"
                @click="handleManage(2)"
                v-btnPermission="'di_0010_add_01'"
                >新增</a-button
            >
            <!-- 表格 -->
            <list-table
                ref="table"
                tableLayout="fixed"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
                <span slot="auditStatus" slot-scope="text, record">
                    <list-status
                        :status="record.auditStatus"
                        :isApproval="true"
                        conversion="en"
                        :text="text"
                    ></list-status>
                </span>
                <template slot="action" slot-scope="text, record">
                    <MoreButton>
                    <a @click="handleManage(0, record)" v-btnPermission="'di_0010_loo_04'">查看</a>
                    <a @click="handleManage(0, record, true)" v-btnPermission="'di_0010_zgl_05'">整改材料</a>
                    <a
                        @click="handleManage(1, record)"
                        v-if="record.auditStatus != 'SUBMITTED'"
                        v-btnPermission="'di_0010_edi_02'"
                        >编辑</a
                    >
                  <a
                    class="del_btn"
                    v-if="record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED'"
                    @click="handleRemove(record.id)"
                    v-btnPermission="'di_0010_del_03'"
                  >删除</a
                  >
                    <span
                        v-btnPermission="'di_0010_edi_02'"
                        v-if="
                            record.auditStatus === 'PAST' ||
                            record.auditStatus === 'SUBMITTED' ||
                            record.auditStatus === 'REJECTED'
                        "
                    >
                        <approval-button :status="record.auditStatus" :id="record.id" text="审批信息"></approval-button>
                    </span>
                    </MoreButton>
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import { getPageProjectSupervision, deleteProjectSupervision } from '@/api/disciplineInspection/supervision' // api
import Selector from '@/components/Select/Selector'
import BasePage from '@/views/basePage' // 基础配置
import SelectTreeUnion from '@/components/Select/SelectTreeUnion' // 工会
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
const searchArr = [
    // 搜索框
    {
        name: '月份',
        type: 'month',
        value: 'month',
        attrs: {
            valueFormat: 'YYYY-MM',
        },
    },
    {
        name: '是否整改',
        value: 'isRectify',
        type: 'select',
        data: [
            {
                label: '是',
                value: '1',
            },
            {
                label: '否',
                value: '0',
            },
        ],
    },
    {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: typeListApproval,
    },
]
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        customRender() {
            return arguments[2] + 1
        },
    },
    {
        title: '月份',
        ellipsis: true,
        dataIndex: 'month',
    },
    {
        title: '分公司',
        ellipsis: true,
        dataIndex: 'branchComName',
    },
    {
        title: '项目',
        ellipsis: true,
        dataIndex: 'projectName',
    },
    {
        title: '审核状态',
        ellipsis: true,
        dataIndex: 'auditStatus',
        scopedSlots: { customRender: 'auditStatus' },
    },
    {
        title: '是否整改',
        ellipsis: true,
        dataIndex: 'rectify',
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: '180px',
        align: 'center',
        scopedSlots: { customRender: 'action' },
    },
]
import { typeListApproval } from '@/utils/util'
export default {
    name:'a'+ Date.now(),
    extends: new BasePage(),
    components: {
        STable,
        SelectTreeUnion,
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {}, // 查询参数
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
                return getPageProjectSupervision(requestParameters).then((res) => {
                    return res
                })
            }, // 加载数据方法 必须为 Promise 对象
            removeApi: { remove: deleteProjectSupervision }, // api
        }
    },
    methods: {
        // 搜索
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        // 操作栏
        handleManage(type, record, report = false) {
            let query = {
                editModel: type,
                report: report,
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: '/disciplineInspection/supervision/projectSupervision/updateProjectSupervision',
                query,
            })
        },
    },
}
</script>
